# Maintainer: gym603 <gui_yuan_miao@163.com>

_realname=protobuf
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=3.12.4
pkgrel=1
pkgdesc="Protocol Buffers (mingw-w64)"
arch=('any')
url="https://github.com/protocolbuffers/protobuf"
license=('3-Clause BSD License')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-six"
         "${MINGW_PACKAGE_PREFIX}-python-setuptools")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-protobuf=${pkgver}")
_archive=${_realname/_/-}-${pkgver}
source=(${_archive}.tar.gz::https://github.com/protocolbuffers/protobuf/archive/v${pkgver}.tar.gz)
sha256sums=('512e5a674bf31f8b7928a64d8adf73ee67b8fe88339ad29adaa3b84dbaa570d8')
noextract=(${_archive}.tar.gz)

prepare() {
  bsdtar -xf ${_archive}.tar.gz || true
}

build() {
  cd "${srcdir}/${_archive}/python"
  ${MINGW_PREFIX}/bin/python setup.py --quiet build
}

package() {
  cd "${srcdir}/${_archive}/python"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python setup.py --quiet install --prefix=${MINGW_PREFIX} --root="${pkgdir}" -O1

  install -Dm644 ../LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
